# coding=utf-8
# Date: 2021/9/6 9:49
from typing import List


# 执行用时：64 ms, 在所有 Python3 提交中击败了64.38%的用户
# 内存消耗：16.2 MB, 在所有 Python3 提交中击败了86.71%的用户
class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        n = len(nums)
        res = [0] * n
        i, j, k = 0, n - 1, n - 1
        while i <= j:
            t = 0
            if abs(nums[i]) > abs(nums[j]):
                t = nums[i]
                i += 1
            else:
                t = nums[j]
                j -= 1
            res[k] = t * t
            k -= 1
        return res


if __name__ == "__main__":
    print(Solution().sortedSquares([-4, -1, 0, 3, 10]))
